﻿// JavaScript Document
$(function(){
	if(document.getElementById('BokeIndex')){
		iFocusChange();
		volution();
		//showAuto();
	}
});
/*大图轮播*/
var show_king_id = 1;
function show_king_list(e,k)
{
    if(show_king_id == k) return true;
        o = document.getElementById("a"+show_king_id);
        o.className = "bg";
    e.className = " ";
    show_king_id = k;
}
var show_kinga_id = 1;
function show_kinga_list(f,l)
{
    if(show_kinga_id == l) return true;
        o = document.getElementById("b"+show_kinga_id);
        o.className = "bg";
    f.className = " ";
    show_kinga_id = l;
}
var size={
	Resize:function (im,nWidth,nHeight ){
		var obj=im||document.getElementById(im);
        var w , h , p1 , p2 ;
        p1 = nWidth / nHeight ;
        p2 = obj.width / obj.height ;
        w = 0 ; h = 0 ;
        if( p1 < p2 ){
           	w = nWidth ;
           	h = nWidth * ( 1 / p2 ) ;
        }
        else{
			if(obj.width<nWidth && obj.height<nHeight){w=obj.width;h=obj.height;}
			else{h = nHeight ;w = nHeight * p2 ;}
        }
        obj.width  = w ;
        obj.height = h ;
		obj.style.marginTop=(nHeight-h)/2+'px';
    },
	autoThumb:function(path,w,h){
		var _self=this;
		$(path).each(function(i){
			var preldimg=new Image();
			preldimg.onload=function(){setTimeout(function(){_self.Resize($(path)[i],w,h);preldimg=null;},50);}
			preldimg.src=$(path)[i].src;
		});	
	}	
}
function iFocusChange(){
	var i=0,foc=$('.Carousel .sow_img li'),cu=foc.length,fox=$('.Carousel .sow_img'),co=fox.length;
	function ifocus(){
		
		fox.parent().find('.Wheel dl').removeClass('ac').mouseover(function(){
			clearTimeout(t);
			var _self=$(this);
			_self.addClass('ac');
			var selfdt=_self.find('dt').text();
			i=selfdt-1;
			ge();
			return false;
		})
	}
	function ge(){
		foc.css('display','none');
		$('.Carousel .Wheel dl').removeClass('ac');
		if(i<cu){
			//alert(i);
			foc.eq(i).css('display','block');
			$('.Carousel .Wheel dl:eq('+i+')').addClass('ac');
			size.autoThumb('.Carousel .sow_img li:eq('+i+') img',490,293)
			i++;
			t=setTimeout(function(){ge()},3000);
		}
		else{i=0;ge();}
	}
	ifocus();ge();
}

/*滚动图片*/
function volution(){
	var volutionID=1;
	var rowN=$('.row ul').length;
	$('.scroll').find('.l').click(function(){
		if(volutionID>=2){
			$('.row').animate({left:-(648*(volutionID-2))},500);
			if(volutionID==2){
				$('.scroll .l').removeClass('l_b').attr('title','左边没有了');
			}else if (volutionID == rowN){
				$('.scroll .r').addClass('r_b').attr('title','向右翻');
			}
			volutionID --;
		}
		this.blur();
		return false;
	}).end().find('.r').click(function(){
		if(volutionID<=(rowN-1)){
			$('.row').animate({left:-(648*volutionID)},500);
			if(volutionID==1){
				$('.scroll .l').addClass('l_b').attr('title','向左翻');
			}else if(volutionID == (rowN-1)) {
					$('.scroll .r').removeClass('r_b').attr('title', '右边没有了');
			}
			volutionID ++;
		}
		this.blur();
		return false;
	});
}
